package com.jrzh.db.data.execute.sys;

import java.util.ArrayList;
import java.util.List;

import org.springframework.context.ApplicationContext;

import com.jrzh.framework.bean.SessionUser;
import com.jrzh.framework.execute.ExecuteBase;
import com.jrzh.mvc.constants.SysConstant;
import com.jrzh.mvc.model.sys.RoleModel;
import com.jrzh.mvc.model.sys.UserModel;
import com.jrzh.mvc.service.sys.manage.SysServiceManage;
public class ExecuteInitData extends ExecuteBase<UserModel>{

	private static final long serialVersionUID = -3301581142737000846L;

	@Override
	public void execute(ApplicationContext context) {
		try {
			SysServiceManage sysServiceManage = (SysServiceManage)context.getBean("sysServiceManage");
			UserModel dbUser = sysServiceManage.userService.findByField("code", "superAdmin");
			if(null == dbUser){
				log.info("###########初始化后台用户基础数据 Begin");
				RoleModel role = new RoleModel();
				role.setCode("sysadmin");
				role.setName("系統管理員");
				role.setRemark("系統管理員");
				role.setSortNum(1);
				role.setIsLock(false);
				role.setIsDisable(false);
				sysServiceManage.roleService.add(role, SessionUser.getSystemUser());
				UserModel user = new UserModel();
				List<RoleModel> roles = new ArrayList<RoleModel>();
				roles.add(role);
				user.setCode("superAdmin");
				user.setName("超級管理員");
				user.setSex(1);
				user.setStatus(SysConstant.USER_STATUS.NORMAL);
				user.setSalt("67260306"); //Default Password : 123456
				user.setPassword("dc5e3aff559e39a8b80345440b13567f3cb3dd96");
				user.setAuditPassword("dc5e3aff559e39a8b80345440b13567f3cb3dd96");
				user.setCardId("421083198906030430");
				user.setTel("13997657127");
				user.setEmail("405677275@qq.com");
				user.setRemark("超級管理員");
				user.setSortNum(1);
				user.setIsDisable(false);
				user.setIsLock(false);
				sysServiceManage.userService.add(user, SessionUser.getSystemUser());
				log.info("###########初始化后台用户基础数据 End");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	@Override
	public Boolean equals(UserModel source, UserModel target) {
		return null;
	}
	
}
